<template>
    <view class="bg-content">
        <div class="page-logistics-company-select">
            <u-search placeholder="请输入搜索关键词" shape="square" v-model="searchKeyword" @search="onSearch" @custom="onSearch"></u-search>
            <u-cell-group>
                <u-cell-item v-for="(item, index) of tbLogisticsCompanyList" :key="item.type" :title="'(' + item.type + ') ' + item.name" :arrow="true"
                             @click="select(item)"></u-cell-item>
            </u-cell-group>

            <div style="padding-top: 10px; padding-bottom: 10px;">
                <u-loadmore :status="pagination.status" bg-color="#eeeeee"/>
            </div>
        </div>
    </view>
</template>

<script>

    import {TbLogisticsCompanyService} from "../../../dev/services/tb-logistics-company.service";
    import {CommonUtil} from "../../../dev/core/utils/common.util";

    export default {
        data() {
            return {
                searchKeyword: '',
                tbLogisticsCompanyList: [],
            }
        },
        onReady() {
            const _self = this;
            this.doRefresh(this.tbLogisticsCompanyList);
        },
        methods: {
            onSearch(event) {
                this.searchKeyword = CommonUtil.trim(this.searchKeyword);
                this.doRefresh(this.tbLogisticsCompanyList);
            },
            select(item) {
                const _self = this;
                this.objParams.logisticsCompanyType = item.type;
                this.objParams.logisticsCompanyName = item.name;
                CommonUtil.toastNavigateBack();
            },
            /**
             * 加载更多数据中
             * @param infiniteScroll
             */
            doInfinite(infiniteScroll) {
                const _self = this;
                new TbLogisticsCompanyService().findTableTbLogisticsCompanyList({
                    pagination: this.pagination,
                    data: {
                        name: this.searchKeyword
                    }
                }).then(result => {
                    _self.pagination.refreshPage(result);
                    _self.tbLogisticsCompanyList = [..._self.tbLogisticsCompanyList, ...result.list];
                });
            }
        },
        // 上拉加载
        onReachBottom: function () {
            if (this.pagination.hasNextPage) {
                this.doInfinite()
            }
        },
    }
</script>

<style lang="scss" scoped>
</style>
